//index.js
//获取应用实例
var app = getApp()
Page({ 
  data: {
    motto: 'Hello World',
    userInfo: {},
    serviceItem: [],
    show_nav: "h_nav",

    selectPerson: true,
    firstPerson: '未选择，查询全部',
    selectArea: false,

  }, 
  //点击选择类型
  clickPerson: function () {
    var selectPerson = this.data.selectPerson;
    if (selectPerson == true) {
      this.setData({
        selectArea: true,
        selectPerson: false,
      })
    } else {
      this.setData({
        selectArea: false,
        selectPerson: true,
      })
    }
  },
  //点击切换
  mySelect: function (e) {
    var that = this;
    var _ism = wx.getStorageSync("_ism"); 

    this.setData({
      firstPerson: e.target.dataset.me,
      firstPersonId: e.target.dataset.hid,
      selectPerson: true,
      selectArea: false,
    })
    wx.request({
      url: app.globalData.api_url + "index.php?ac=hapi&ts=js_list",
      data: { 
        hid: e.target.dataset.hid,
         ism: _ism,
         },
      header: { 'content-type': 'application/json' },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          orderList: res.data.list,
          jsTotalMoney: res.data.jsTotalMoney,
          jsFenchengMoney: res.data.jsFenchengMoney,
          hairdList: res.data.hairdList
        })
        console.log(res.data);
      }

    })
  },


  show_nav: function (e) {
    
          var that = this;
          that.setData({
            show_nav: 'Haircut_nav'
          });
  },
  onLoad: function (e) {
    var that = this;
    var _ism = wx.getStorageSync("_ism");
    var member_id = wx.getStorageSync("_hairdresser_id");

    //调用应用实例的方法获取全局数据
  that.setData({
      userInfo: wx.getStorageSync("userInfo"),
    });
     var pages = getCurrentPages();
                  var prevPage = pages[pages.length - 2]; 
                  prevPage.setData({
                    show_nav: 'h_nav'
                  });
                  
      wx.showLoading({
        title: '加载中',
      }),
      wx.request({
      url: app.globalData.api_url + "index.php?ac=hapi&ts=js_list",
        data: { 
          ism: _ism,
          hid: member_id,
          orderStat: 0,
         },
        header: { 'content-type': 'application/json' },
        success: function (res) {
          wx.hideLoading();
          that.setData({
            orderList: res.data.list,
            jsTotalMoney: res.data.jsTotalMoney,
            jsFenchengMoney: res.data.jsFenchengMoney,
            hairdList: res.data.hairdList
          })
          console.log(res.data);
        }

      })
      , setTimeout(function () {
        wx.hideLoading()
      }, 3000)
  },
  jsOrder: function (e) {
    var that = this;
    wx.showModal({
      title: '结算',
      content: '确定结算!',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: app.globalData.api_url + "index.php?ac=hapi&ts=js_opt",
            data: {
              order_id: e.currentTarget.dataset.orderId,
              jsstat: 1
            },
            method: "GET",
            header: { 'content-type': 'application/json' },
            success: function (res) {
              that.setData({
                orderList: res.data
              })
              console.log(res.data);
            }

          })
        } else {
          console.log('已取消')
        }
      }
    })



  },

})
